package com.bo.ivolatile;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: gpb
 * @Date: 2024/7/31 10:52
 * @Description:
 */
public class ILock {

    static boolean flag = true;
    static Lock lock = new ReentrantLock();

    public static void main (String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            while (flag) {
                lock.lock();
                try {
                } catch (Exception e) {
                    throw new RuntimeException(e);
                } finally {
                    lock.unlock();
                }
            }
            System.out.println(Thread.currentThread().getName() + "线程结束");
        });
        thread.start();
        Thread.sleep(100);
        flag = false;
    }
}
